package tsj.ai.alibaba.data.analysis.util;

import tsj.ai.alibaba.data.analysis.common.connector.config.DbConfig;
import tsj.ai.alibaba.data.analysis.entity.Datasource;

/**
 * @author taoshujian
 * @version 1.0
 * @since 2025-11-14 16:15:18
 */
public class SchemaProcessorUtil {
    public static DbConfig createDbConfigFromDatasource(Datasource datasource) {
        DbConfig dbConfig = new DbConfig();

        // Set basic connection information
        dbConfig.setUrl(datasource.getConnectionUrl());
        dbConfig.setUsername(datasource.getUsername());
        dbConfig.setPassword(datasource.getPassword());

        // TODO Set database type need to be optimized
        if ("mysql".equalsIgnoreCase(datasource.getType())) {
            dbConfig.setConnectionType("jdbc");
            dbConfig.setDialectType("mysql");
        }
        else if ("h2".equalsIgnoreCase(datasource.getType())) {
            dbConfig.setConnectionType("jdbc");
            dbConfig.setDialectType("h2");
        }
        // Support for other database types can be extended here

        // Set Schema as the database name of the data source
        dbConfig.setSchema(datasource.getDatabaseName());

        return dbConfig;
    }

    /**
     * Private constructor to prevent instantiation.
     */
    private SchemaProcessorUtil() {
        throw new AssertionError("Cannot instantiate utility class");
    }

}
